package com.example.provide;

import com.example.utils.RabbitMqUtils;
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.io.IOException;

public class Provider {

    //普通交换机
    private static final String NORMAL_EXCHANGE = "normal-exchange";

    public static void main(String[] args) {
        //获取连接
        Connection connection = RabbitMqUtils.getConnection();
        Channel channel = null;
        try {
            //获取信道
            channel = connection.createChannel();
            //发送死信消息 设置TTL时间(毫秒)
            AMQP.BasicProperties properties =
                    new AMQP.BasicProperties()
                            .builder().expiration("10000").build();
            for (int i = 0; i < 10; i++) {
                channel.basicPublish(NORMAL_EXCHANGE, "key1", properties, ("msg" + i).getBytes());
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            RabbitMqUtils.close(connection, channel);
        }
    }

}
